﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AntikCompta
{
    public partial class CalcWnd : Form
    {
        private decimal mCurrentValue;
        char mSign;
        public CalcWnd()
        {
            InitializeComponent();
            Resete();
        }

        private void txt_afficheur_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar == '+') || (e.KeyChar == '-') ||
                (e.KeyChar == '*') || (e.KeyChar == '/'))
            {
                Calculate();
                mSign = e.KeyChar;
            }
            else if (e.KeyChar == (char)Keys.Enter)
            {
                Calculate();
                txt_afficheur.Text = mCurrentValue + "";
                mSign = ' ';
                txt_afficheur.SelectAll();
            }
        }

        private void Calculate()
        {
            if (mSign == ' ')
                mCurrentValue = txt_afficheur.DecimalValue;
            else if (mSign == '+')
                mCurrentValue += txt_afficheur.DecimalValue;
            else if (mSign == '-')
                mCurrentValue -= txt_afficheur.DecimalValue;
            else if (mSign == '*')
                mCurrentValue *= txt_afficheur.DecimalValue;
            else if (mSign == '/')
            {
                if( txt_afficheur.DecimalValue != 0 )
                    mCurrentValue /= txt_afficheur.DecimalValue;
            }
            txt_afficheur.Text = "";
        }

        private void bt_ce_Click(object sender, EventArgs e)
        {
            Resete();
        }

        private void Resete()
        {
            mSign = ' ';
            mCurrentValue = 0;
            txt_afficheur.Text = "";
        }

        private void bt_0_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "0";
        }

        private void bt_1_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "1";
        }

        private void bt_2_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "2";
        }

        private void bt_3_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "3";
        }

        private void bt_4_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "3";
        }

        private void bt_5_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "5";
        }

        private void bt_6_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "6";
        }

        private void bt_7_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "7";
        }

        private void bt_8_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "8";
        }

        private void bt_9_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text += "9";
        }

        private void bt_enter_Click(object sender, EventArgs e)
        {
            Calculate();
            txt_afficheur.Text = mCurrentValue + "";
            mSign = ' ';
            txt_afficheur.SelectAll();
        }

        private void bt_plus_Click(object sender, EventArgs e)
        {
            Calculate();
            mSign = '+';
        }

        private void bt_moins_Click(object sender, EventArgs e)
        {
            Calculate();
            mSign = '-';
        }

        private void bt_mult_Click(object sender, EventArgs e)
        {
            Calculate();
            mSign = '*';
        }

        private void bt_div_Click(object sender, EventArgs e)
        {
            Calculate();
            mSign = '/';
        }

        private void bt_toM1_Click(object sender, EventArgs e)
        {
            txt_m1.Text = txt_afficheur.Text;
        }

        private void bt_toM2_Click(object sender, EventArgs e)
        {
            txt_m2.Text = txt_afficheur.Text;
        }

        private void bt_toM3_Click(object sender, EventArgs e)
        {
            txt_m3.Text = txt_afficheur.Text;
        }

        private void bt_toM4_Click(object sender, EventArgs e)
        {
            txt_m4.Text = txt_afficheur.Text;
        }

        private void bt_toM5_Click(object sender, EventArgs e)
        {
            txt_m5.Text = txt_afficheur.Text;
        }

        private void bt_toM6_Click(object sender, EventArgs e)
        {
            txt_m6.Text = txt_afficheur.Text;
        }

        private void bt_toM7_Click(object sender, EventArgs e)
        {
            txt_m7.Text = txt_afficheur.Text;
        }

        private void bt_toM8_Click(object sender, EventArgs e)
        {
            txt_m8.Text = txt_afficheur.Text;
        }

        private void bt_toM9_Click(object sender, EventArgs e)
        {
            txt_m9.Text = txt_afficheur.Text;
        }

        private void bt_toM10_Click(object sender, EventArgs e)
        {
            txt_m10.Text = txt_afficheur.Text;
        }

        private void bt_toM11_Click(object sender, EventArgs e)
        {
            txt_m11.Text = txt_afficheur.Text;
        }

        private void bt_toM12_Click(object sender, EventArgs e)
        {
            txt_m12.Text = txt_afficheur.Text;
        }

        private void bt_M1_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m1.Text;
        }

        private void bt_M2_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m2.Text;
        }

        private void bt_M3_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m3.Text;
        }

        private void bt_M4_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m4.Text;
        }

        private void bt_M5_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m5.Text;
        }

        private void bt_M6_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m6.Text;
        }

        private void bt_M7_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m7.Text;
        }

        private void bt_M8_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m8.Text;
        }

        private void bt_M9_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m9.Text;
        }

        private void bt_M10_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m10.Text;
        }

        private void bt_M11_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m11.Text;
        }

        private void bt_M12_Click(object sender, EventArgs e)
        {
            txt_afficheur.Text = txt_m12.Text;
        }

        private void bt_expand_Click(object sender, EventArgs e)
        {
            if (this.Width == 230)
            {
                this.Width = 453;
            }
            else
            {
                this.Width = 230;
            }
        }

    }
}
